﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link href="~/layui-v2.6.8/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/layui-v2.6.8/layui-v2.6.8/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

    <form class="layui-form" action="">

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:crimson">*</span>请假类型:</label>

            <div class="layui-input-block">
                <select name="genreId" lay-filter="aihao">
                    <option value="">全部</option>
                    <option value="0">待审核</option>
                    <option value="1" selected="selected">已通过</option>
                    <option value="2" selected="selected">未通过</option>
                </select>
            </div>
        </div>

        <div>
            <div class="layui-inline">
                <label class="layui-form-label"><span style="color:crimson">*</span>开始时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="Times" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span style="color:crimson">*</span>结束时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="Times" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:crimson">*</span>请假天数:</label>
            <div class="layui-input-block">
                <input type="text" name="days" lay-verify="required" lay-reqtext="请假天数是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span style="color:crimson">*</span>请假事由:</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="incident" class="layui-textarea"></textarea>
            </div>
        </div>

        <div>
            <label class="layui-form-label">附件:</label>
            <button type="button" class="layui-btn layui-btn-danger" id="test7" name="uploadFiles"><i class="layui-icon"></i>上传文件</button>
            <div class="layui-inline layui-word-aux">
                这里以限制 60KB 为例
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">审批人:</label>
            <div class="layui-input-block">
                <input type="text" name="auditor" lay-verify="required" lay-reqtext="审批人是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">知会人:</label>
            <div class="layui-input-block">
                <input type="text" name="informPerson" lay-verify="required" lay-reqtext="知会人是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>



    <link href="~/layui-v2.6.8/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/layui-v2.6.8/layui-v2.6.8/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script>

        //（4） 前端：浏览器请求服务器的时候，要带上JWT
        $.ajaxSetup({
            beforeSend: function (xhr) {
                if (localStorage.getItem("token") !== null) {
                    //（4） 前端：浏览器请求服务器的时候，要带上JWT
                    xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("token"));
                }
            }
        });

        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            //日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });

           

            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }
                , pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });


            //监听提交
            form.on('submit(demo1)', function (data) {
              
                $.ajax({
                    url: 'https://localhost:44398/api/DicAPI/Add',
                    type: 'post',
                    data: data.field,
                    success: function (d) {
                        console.log(d);
                        if (d > 0) {
                            layer.msg("添加成功", function () {
                                parent.location.href = "/ApplicationWeb/Index";
                            })
                        } else {
                            layer.msg("添加失败");
                            return;
                        }
                    }
                })
               
                return false;
            });

            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });

        });
    </script>

</body>
</html>
